package com.zhida.smartcontrol.pagehome.search;

import android.text.TextUtils;

import com.alibaba.fastjson.JSON;
import com.yanzhenjie.kalle.Params;
import com.zhida.smartcontrol.common.Api;
import com.zhida.smartcontrol.knet.KalleCallBack;
import com.zhida.smartcontrol.mvp.BasePresenterImpl;
import com.zhida.smartcontrol.pagehome.ProjectResultBean;

import java.util.List;

/**
 * author: tanjianpei
 * date: 2019/10/10 010 14:44
 * description:
 */
public class SearchPresenter extends BasePresenterImpl<SearchContract.View> implements SearchContract.Presenter {

    @Override
    public void requestByProjectAndKeyWord(String projectBaseId, String keywords) {
        if (TextUtils.isEmpty(projectBaseId)) {
            mView.showMsg("错误的项目id");
            return;
        }
        if (TextUtils.isEmpty(keywords)) {
            mView.showMsg("请输入设备IMEI");
            return;
        }
        Params params = Params.newBuilder()
                .add("projectBaseId", projectBaseId)
                .add("keywords", keywords)
                .build();
        mKalleCenter.get(Api.FIND_PROJECT, params, true, new KalleCallBack() {
            @Override
            public void onSuccess(String result, String msg) {
                List<ProjectResultBean> resultBeans = JSON.parseArray(result, ProjectResultBean.class);
                mView.showList(resultBeans);
            }

            @Override
            public void onFailed(String msg) {
                mView.showMsg(msg);
            }
        });
    }

}
